using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for ProceduresAdaptor.
	/// </summary>
	public class ProceduresAdaptor : Adaptor, IRefreshable
	{
    private ProcedureCollection procedures;
		public ProceduresAdaptor(ProcedureCollection procedures)
		{
      this.procedures = procedures;
		}

    public override void AddChildren(TreeNode node)
    {
      foreach (Procedure proc in procedures)
      {
        TreeNode procNode = TreeNodeFactory.CreateTreeNode(new ProcedureAdaptor(proc));
        node.Nodes.Add(procNode);
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 8;
      }
    }

    public override string Text
    {
      get
      {
        return "Procedures (" + procedures.Count + ")";
      }
    }

    public override Control GetRenderer()
    {
      ProceduresControl control = new ProceduresControl();
      control.LoadProcedures(procedures);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    public override object Object
    {
      get
      {
        return procedures;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      procedures.Refresh();
    }

    #endregion
  }
}
